using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using trytotest.Models;

namespace trytotest.Controllers
{   
    public class NewArticlesController : Controller
    {
        private trytotestContext context = new trytotestContext();

        //
        // GET: /NewArticles/

        public ViewResult List()
        {
            return View(context.NewArticles.ToList());
        }

        //
        // GET: /NewArticles/Details/5

        public ViewResult Details(int id)
        {
            Models.NewArticles newarticles = context.NewArticles.Single(x => x.ID == id);
            return View(newarticles);
        }

        //
        // GET: /NewArticles/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /NewArticles/Create

        [HttpPost]
        public ActionResult Create(Models.NewArticles newarticles)
        {
            if (ModelState.IsValid)
            {
                context.NewArticles.Add(newarticles);
                context.SaveChanges();
                return RedirectToAction("List");  
            }

            return View(newarticles);
        }
        
        //
        // GET: /NewArticles/Edit/5
 
        public ActionResult Edit(int id)
        {
            Models.NewArticles newarticles = context.NewArticles.Single(x => x.ID == id);
            return View(newarticles);
        }

        //
        // POST: /NewArticles/Edit/5

        [HttpPost]
        public ActionResult Edit(NewArticles newarticles)
        {
            if (ModelState.IsValid)
            {
                context.Entry(newarticles).State = EntityState.Modified;
                context.SaveChanges();
                return RedirectToAction("List");
            }
            return View(newarticles);
        }

        //
        // GET: /NewArticles/Delete/5
 
        public ActionResult Delete(int id)
        {
            Models.NewArticles newarticles = context.NewArticles.Single(x => x.ID == id);
            return View(newarticles);
        }

        //
        // POST: /NewArticles/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            Models.NewArticles newarticles = context.NewArticles.Single(x => x.ID == id);
            context.NewArticles.Remove(newarticles);
            context.SaveChanges();
            return RedirectToAction("List");
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing) {
                context.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}